package com.qf.service.impl;

import com.qf.dao.GoodsDao;
import com.qf.pojo.Goods;
import com.qf.pojo.GoodsType;
import com.qf.pojo.resp.BaseResult;
import com.qf.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    GoodsDao goodsDao;

    @Override
    public BaseResult findAllGoods() {
        try {
            List<Goods> goodsList = goodsDao.findAllGoods();
            return new BaseResult(1, "查询成功!", goodsList);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0, "查询失败!", null);
        }
    }

    @Override
    public BaseResult findOneById(int gid) {
        try {
            Goods one = goodsDao.findOneById(gid);
            return new BaseResult(1, "查询成功!", one);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0, "查询失败!", null);
        }
    }

    @Override
    public BaseResult findGoodsByType(String t_id) {
        try {
            List<Goods> goods = goodsDao.findGoodsByType(t_id);
            return new BaseResult(1, "查询成功!", goods);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0, "查询失败!", null);
        }
    }

    @Override
    public BaseResult findAllType() {
        try {
            List<GoodsType> goodsTypes = goodsDao.findAllType();
            return new BaseResult(1, "查询成功!", goodsTypes);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(0, "查询失败!", null);
        }
    }
}
